import com.alibaba.fastjson.JSONObject;
import faceService.AddFace;
import faceService.CreatePerson;
import org.apache.commons.collections.map.HashedMap;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/28.
 */
public class main {
    public static void main(String[] args) throws Exception {
        List<File> fileList = new ArrayList<File>();
        Map<String,  List<String>> personImgs = new HashedMap();
        Map<String, String> personPath = new HashedMap();
        File file = new File("C:\\Users\\Administrator\\Desktop\\facePic");
        if (file.exists()) {
            File[] files = file.listFiles();
            for (File file1 : files) {
                if (file1.isDirectory()) {
                    try {
                        fileList.add(file1);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        for (File file1 : fileList) {
            List<String> filePathLists = new ArrayList<String>();
            String personName = file1.getName();
            File[] files = file1.listFiles();
            for (File file2 : files) {
                if (!file2.isDirectory()) {
                    try {
                        filePathLists.add(file2.getAbsolutePath());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            personImgs.put(personName, filePathLists);
            personPath.put(personName, file1.getAbsolutePath());
        }

        CreatePerson createPerson = new CreatePerson();
        AddFace addFace = new AddFace();

        for (Map.Entry<String, List<String>> entry : personImgs.entrySet()) {
            JSONObject jsonObject =  createPerson.createPerson(entry.getKey(), entry.getKey(), entry.getValue().get(0));
            if (jsonObject.get("message").equals("OK")) {
                addFace.addFace(entry.getKey(), personPath.get(entry.getKey()));
            } else if (jsonObject.get("message").equals("ERROR_PERSON_EXISTED")) {
                addFace.addFace(entry.getKey(), personPath.get(entry.getKey()));
            }
        }

        System.out.print("111");

    }
}
